package com.lyon.custom.autoconfiguration;

import com.lyon.custom.config.LyonConfigProperties;
import com.lyon.custom.core.LyonConfigManager;
import com.lyon.custom.core.LyonPropertySourceLocator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LeeYan9
 * @since 2021-11-26
 */
@ConditionalOnProperty(prefix = "lyon.config", name = "enable", havingValue = "true")
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(LyonConfigProperties.class)
public class LyonConfigAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    LyonConfigManager lyonConfigManager(LyonConfigProperties lyonConfigProperties) {
        return new LyonConfigManager(lyonConfigProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    LyonPropertySourceLocator lyonPropertySourceLocator(LyonConfigManager lyonConfigManager, LyonConfigProperties lyonConfigProperties) {
        return new LyonPropertySourceLocator(lyonConfigManager, lyonConfigProperties);
    }

}
